<script setup>
import { provide } from 'vue';
import axios from 'axios';
import { useLoginedStore } from '@/stores/logined';

const loginedStore = useLoginedStore();

const instance = axios.create({ timeout: 1000 } );

const fulfilled = (config) => {
    const token = loginedStore.token;
    if( token ) {
        config.headers.set('Authorization', `Bearer ${token}`)
    }
    return config;
}

const rejected = (error) => {
    Promise.reject(error);
}

instance.interceptors.request.use(fulfilled, rejected);
// 向子组件提供一个名称为 $http 的对象
provide('$http', instance);
</script>

<template>
    <router-view></router-view>
</template>

<style>
body {
    margin: 0;
}
</style>